package com.holic.spring.custom.exception;

import graphql.GraphQLError;
import graphql.execution.DataFetcherExceptionHandler;
import graphql.execution.DataFetcherExceptionHandlerParameters;
import graphql.execution.DataFetcherExceptionHandlerResult;

import java.util.concurrent.CompletableFuture;

/**
 * @ClassName CustomDataFetcherExceptionHandler
 * @Description
 * @Author Neil
 * @Date 2024/11/14 17:38
 * @Version V1.0
 **/
public class CustomDataFetcherExceptionHandler implements DataFetcherExceptionHandler {

    @Override
    public CompletableFuture<DataFetcherExceptionHandlerResult> handleException(DataFetcherExceptionHandlerParameters handlerParameters) {
        String message = handlerParameters.getException().getMessage();
        DataFetcherExceptionHandlerResult result = DataFetcherExceptionHandlerResult.newResult()
                .error(new CustomGraphQLError(message, "ERROR"))
                .build();
        System.out.println(handlerParameters.getArgumentValues());
        return CompletableFuture.completedFuture(result);
    }

}
